package cn.tedu.collection;

import java.util.*;

/**
 * @author :Colin
 * @version 创建时间: 2021/6/21 14:13
 */
public class TestArrayList {
    public static void main(String[] args) {
        ArrayList<Integer> list =new ArrayList<>();
        //数组的初始容量10
        list.add(100);
        list.add(200);
        list.add(300);
        list.add(400);
        list.add(200);
        //list.clear();
        System.out.println(list.contains(100));
        System.out.println(list.get(1));//200
        System.out.println(list.indexOf(200));
        System.out.println(list.lastIndexOf(200));
        System.out.println(list.remove(1));
        //System.out.println(list.remove(300);报错，下标越界
        System.out.println(list.remove(Integer.valueOf(300)));//手动装箱
        System.out.println(list);
        System.out.println(list.size());
        System.out.println(Arrays.toString(list.toArray()));//list转数组
        System.out.println("迭代方式");
        System.out.println("方式1；for循环");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println("方式2；for高效循环");
        for(Integer i:list){
            System.out.println(i);
        }
        System.out.println("方式3；interator");
        Iterator<Integer> it =list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("方式4；listInterator");
        ListIterator<Integer> it2 =list.listIterator();
        while(it2.hasNext()){
            System.out.println(it2.next());
        }


    }
}
